/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mobiubiq.directory.client.widget;

import java.io.IOException;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import org.kalmeo.kuix.widget.Picture;

/**
 *
 * @author Marnix Renne
 */
public class Image extends Picture {

    public static final String IMAGE_TAG = "image";

    public Image() {
        super();
    }

    public Picture setSource(String source) {
        if (source.startsWith("http://") || source.startsWith("https://")) {
            try {
                HttpConnection conn = (HttpConnection) Connector.open(source);
                javax.microedition.lcdui.Image image = javax.microedition.lcdui.Image.createImage(conn.openInputStream());
                conn.close();
                this.setImage(image);
                return this;
            } catch (IOException ex) {
                return this;
            }
        } else {
            return super.setSource(source);
        }
    }
}
